package com.ruanyuan.springboot.dao;

import com.ruanyuan.springboot.pojo.Car;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 汽车实体数据访问层
 */
public interface CarDao {
    /**
     * 多条件查询
     */
    @Results(id = "employee" ,value = {
            @Result(property = "id",column = "id"),
            @Result(property = "color",column = "color"),
            @Result(property = "name",column = "name"),
            @Result(property = "employee",column = "employeeid",one = @One(select = "com.ruanyuan.springboot.dao.EmployeeDao.selectEmployeeid"))
    })
    @Select("select * from car limit #{page},#{limit}")
    public List<Car> selectCar(@Param("page")int page, @Param("limit")int limit);
    /**
     * 根据用户id查询车辆信息
     */
    @Select("SELECT * FROM car WHERE employeeid=#{employeeid}")
    public List<Car> selectCaremployeeid(String employeeid);
    /**
     * 多条件查询个数
     */
    @Select("SELECT count(*) FROM car")
    public int selectCarCount();

    /**
     * 添加车辆信息
     * @param car
     * @return
     */
    @Insert("INSERT INTO car VALUE(NULL,#{color},#{name},#{Employee.id})")
    public  int insertCar(Car car);
    /**
     * 修改车辆信息
     */
    @Update("update car set color=#{color},name=#{name},employeeid=#{Employee.id} where id=#{id}")
    public int updateCar(Car car);
    /**
     * 根据id单个删除车辆信息
     */
    @Delete("DELETE FROM car WHERE id = #{id}")
    public int deleteCarById(String id);
    /**
     * 根据id批量删除车辆信息
     */
    @DeleteProvider(type = Batch.class, method = "batchDeleteCar")
    public int deleteCarIds(List<String>  addids);
    /**
     * 根据用户id批量删除车辆信息
     */
    public int deleteCarAddressIds(List<Integer>  addressids);
    /**
     * 单个根据用户id删除车辆信息
     */
    @Delete("DELETE FROM car WHERE employeeid = #{addid}")
    public int deleteCarByEmployeeId(String addid);
    /**
     * 通过用户id查询车辆总个数
     */
    @Select("SELECT count(*) FROM car WHERE  employeeid= #{employeeid}")
    public int selectCountemployeeid();
}
